<?php

/**
 * 前台公共库文件
 * 主要定义前台公共函数库
 */

function geticon($id){
	$v=M('usermember')->Field('icon')->find($id);
	$icon=$v['icon'];
	$picture=M('picture')->Field('path')->find($icon);
	if($picture){
		return $picture['path'];
	}
	return '/Public/Home/images/def.jpg';
}
/**
 * 检测验证码
 */
function check_verify($code, $id = 1){
	$verify = new \Think\Verify();
	return $verify->check($code, $id);
}

/**
 * 获取列表总行数
 */
function get_list_count($category, $status = 1){
    static $count;
    if(!isset($count[$category])){
        $count[$category] = D('Document')->listCount($category, $status);
    }
    return $count[$category];
}




/**
 * 获取段落总数
 */
function get_part_count($id){
    static $count;
    if(!isset($count[$id])){
        $count[$id] = D('Document')->partCount($id);
    }
    return $count[$id];
}
//生成验证码
function generate_code($length = 4) {
	return rand(pow(10,($length-1)), pow(10,$length)-1);

}

/**
 * 获取导航URL
 */
function get_nav_url($url){
    switch ($url) {
        case 'http://' === substr($url, 0, 7):
        case '#' === substr($url, 0, 1):
            break;        
        default:
            $url = U($url);
            break;
    }
    return $url;
}







